package whisper.service.auth.shiro.realm.jwt;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import whisper.support.user.domain.User;
import whisper.support.user.service.PermissionService;
import whisper.support.user.service.RoleService;
import whisper.support.user.service.UserService;

import java.util.Set;

/**
 * Created by JT on 2018/5/31
 */
public class ManagerJWTRealm extends JWTRealm {

    @Autowired
    @Lazy
    private UserService userService;

    @Autowired
    @Lazy
    private RoleService roleService;

    @Autowired
    @Lazy
    private PermissionService permissionService;

    @Override
    public User findUser(String username) {
        return userService.findByUsername(username);
    }

    @Override
    public Set<String> findRoles(String username) {
        return roleService.findByUsername(username);
    }

    @Override
    protected Set<String> findPermissions(String username) {
        return permissionService.findByUsername(username);
    }
}
